﻿using System;

namespace ProjetoComperio.Framework.Extensions
{
    public static class EntityObjectExtensions
    {

        /// <summary>
        /// This method copies only value types and string
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="from"></param>
        /// <param name="source"></param>
        public static void CopyValuesFrom<T>(this T from, T source) where T : new()
        {

            foreach (var item in source.GetType().GetProperties())
            {

                if (!item.CanWrite)
                    continue;

                if (!item.PropertyType.IsValueType || !(item.PropertyType == typeof(String)))
                    continue;

                item.SetValue(from, item.GetValue(source, null), null);
            }
        }




    }
}
